import {observable, action} from "mobx";
import {Form} from "weaver-mobile-page";
import * as API from "../../api";

export default class ProjectFormStore {
    @observable isLoading = true;
    @observable prjid;
    @observable projectForm = new Form.Store();
    @action
    init = (prjid, viewtype) => {
        this.prjid = prjid;
        this.viewtype = viewtype;
        this.getProjectForm(prjid, viewtype);
    }
    @action
    getProjectForm = (prjid) => {
        this.isLoading = true;
        const params = {
            "prjid": prjid
        };
        this.projectForm = new Form.Store();
        API.getProjectForm(params).then(action(res => {
            this.isLoading = false;
            if (res.isright) {
                this.projectForm.initForm(res.fieldinfo, `/ProjectDetails/0/${this.prjid}`);
            }
        }))
    };

    @action
    getParams = (form) => {
        return form.formParams;
    };

    @action
    updateField = (form, key, value) => {
        form.updateField(key, value);
    };
    @action
    clearForm = (form) => {
        form.resetFields();
    };
}
